// n:UDOP_ReadPARDUMP,r:SourcePARDUMP1,z:1
#ifndef _UDOP_ReadPARDUMP_H_
#define _UDOP_ReadPARDUMP_H_

#include <string>
#include <DPS/PH/DpsPE.h>
#include <DPS/PH/DpsSignal.h>
#include <DPS/PH/DpsOP.h>
#include <DPS/PH/DpsPE.h>

#include "SourcePARDUMP1.h"

#undef DPS_NUM_INPUT_PORTS
#define DPS_NUM_INPUT_PORTS 0
#undef DPS_NUM_OUTPUT_PORTS
#define DPS_NUM_OUTPUT_PORTS 1

#include "UDOP_ReadPARDUMP_includes.h"

namespace DPS {

class UDOP_ReadPARDUMP 
: public DpsOP {
  typedef DpsOP UdopParent;

public:
  UDOP_ReadPARDUMP(DpsPE & ppe, DpsOPContext & cx) 
    : UdopParent(ppe,cx)
    , submit0(this, 0), punctuate0(this, 0)
  {
    initializeOperator();
  }
  virtual ~UDOP_ReadPARDUMP() {
    finalizeOperator();
  }

  inline unsigned getNumberOfInputPorts() const {
    return 0;
  }

  inline unsigned getNumberOfOutputPorts() const {
    return 1;    
  }

 /*
  * Function used to process cmd arguments                         
  */
  void processCmdArgs(const std::string & args);

 /*
  * Function used to initialize the operator
  */
  void initializeOperator();

 /*
  * Function used to finalize the operator
  */
  void finalizeOperator();


 /*
  * Functions used to process input tuples
  */
#ifdef DPS_PORT_GENERIC_UDOP
  void processInput(const DpsTuple & tuple, unsigned iport);
#endif
  void process();

  typedef SourcePARDUMP1_t OPort0_t;
  /*
   * This delegate is used to submit output tuples on port 0
   * E.g.: OPort0_t otuple; ...; submit0(otuple);
   */
  DpsSignal<void, const OPort0_t> submit0;

  /*
   * This delegate is used to send punctuations on port 0
   */
  DpsSignal<void, const Punctuation::Value> punctuate0;


 /*
  * Function used to submit tuples
  */
#ifdef DPS_PORT_GENERIC_UDOP
  void submit(const DpsTuple & tuple, unsigned opidx) {
    if(opidx>=getNumberOfOutputPorts())
      THROW(IllegalArgument, "Invalid port index '" << opidx << "' (valid range is [0.."<<getNumberOfOutputPorts()<<"])");
    switch(opidx) {
    case 0: {
      const OPort0_t * tuple0 = dynamic_cast<OPort0_t const*>(&tuple);
      if(tuple0==NULL) THROW(IllegalArgument, "Invalid tuple type '" << typeid(tuple).name() << "' passed to the submit function, was expecting 'OPort0_t'");
      submit0(*tuple0);
      break;
    }
    default: break;
    };
  }
  DpsTuple * newOutputTuple(unsigned opidx) const {
    if(opidx>=getNumberOfOutputPorts())
      THROW(IllegalArgument, "Invalid port index '" << opidx << "' (valid range is [0.."<<getNumberOfOutputPorts()<<"])");
    switch(opidx) {
    case 0: 
      return new OPort0_t();
    default: break;
    };
    return NULL;
  }
#endif

private:
  UTILS_NAMESPACE::Mutex mutex;

#include "UDOP_ReadPARDUMP_members.h"

};

};

#endif /* _UDOP_ReadPARDUMP_H_ */

